// index.js
// 获取应用实例
const app = getApp()
const request = require('../../utils/request.js')
Page({
  data: {
    ppData:[
      {
        id:'1',
        productBrand:'MLB',
        productActualAmountNo:'51313',
        productDiscount:'1'
      },
      {
        id:'2',
        productBrand:'耐克',
        productActualAmountNo:'51313',
        productDiscount:'1'
      }
    ],
    typesData:[{
      "id": 10,
      "productActualAmountNo": 10,
      "productClass": "",
      "productBrand": "帽子",
      "productDiscount": 1,
      "type": 1
    }],
    visible2: true,
    goodsNum:1,
    searchValue: "",
    text: "今日汇率：1美元=1808.32韩币；1人民币=800.32韩币",
    marqueePace: 1, //滚动速度
    marqueeDistance: 0, //初始滚动距离
    marquee_margin: 70,
    size: 14,
    interval: 30, // 时间间隔
  },
  // 事件处理函数
  bindViewTap() {

  },
  onLoad() {
    


    // 汇率
    // request("GET","/exchangeRate/select")
    // .then(res =>{
    //   this.setData({
    //     text: "今日汇率：1美元 = "+res.result[0].dollarToKc+"韩币；1人民币 = "+res.result[0].rmbToKc+"韩币"
    //   });
    // })
  },
  onShow() {
    var that = this;
    var length = that.data.text.length * that.data.size; //文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth; // 屏幕宽度
    // console.log(length, windowWidth);
    that.setData({
      length: length,
      windowWidth: windowWidth
    });
    that.scrolltxt(); // 第一个字消失后立即从右边出现
  },
  scrolltxt: function () {
    var that = this;
    var length = that.data.length; //滚动文字的宽度
    var windowWidth = that.data.windowWidth; //屏幕宽度
    if (length > windowWidth) {
      var interval = setInterval(function () {
        var maxscrollwidth = length; //滚动的最大宽度，文字宽度+间距，如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
        var crentleft = that.data.marqueeDistance;
        if (crentleft < maxscrollwidth) { //判断是否滚动到最大宽度
          that.setData({
            marqueeDistance: crentleft + that.data.marqueePace
          })
        } else {
          //console.log("替换");
          that.setData({
            marqueeDistance: 0 // 直接重新滚动
          });
          clearInterval(interval);
          that.scrolltxt();
        }
      }, that.data.interval);
    } else {
      that.setData({
        marquee_margin: "2000"
      }); //只显示一条不滚动右边间距加大，防止重复显示
    }
  },

  
  //搜索
  search() {
    console.log("搜索")
  },
  searchBlur() {
    console.log("1111")
    this.setData({
      searchValue: ""
    })
  },
  searchCancel() {
    this.setData({
      searchValue: ""
    })
  },
  // 切换商品分类
  typesChange(e) {
    console.log(e.detail.key)
  },
  // 切换品牌分类
  ppChange(e) {
    console.log(e.detail.key)
  },
  goodsTap() {
    this.setData({
      visible2: true,
    })
  },
  onClose() {
    this.setData({
      visible2: false,
    })
  },
  goodsNum(e){
    this.setData({
      goodsNum:e.detail.value
    })
    
  },
  buyFnc(e){
    console.log(this.data.goodsNum)
  },
  chooseAdders(){
    wx.chooseAddress({
      success (res) {
        console.log(res.userName)
        console.log(res.postalCode)
        console.log(res.provinceName)
        console.log(res.cityName)
        console.log(res.countyName)
        console.log(res.detailInfo)
        console.log(res.nationalCode)
        console.log(res.telNumber)
      }
    })
  }
})